package com.atguigu.scala.chapter8

import scala.util.Random

/**
 * @author lizikuan
 * @date 2021/5/25 18:12
 */
object $04_MatchType {
  class Person(val name:String,val age:Int)
  def main(args: Array[String]): Unit = {
    val list = Array("hello", 10, 99.9, "world", "lol",
      new Person("zhangfei",20),
      new Person("zhaoyun",18) )
    val index = Random.nextInt(list.size)
    val value = list(index)
    value match {
      case x:String => println(s"${x}")
      case x:Int => println(s"x = ${x}")
      case x:Double => println(s"x = ${x}")
      case x:Person if(x.name=="zhaoyun") => println(s"x = ${x}")
      case x:Person if(x.name=="zhangfei") => println(s"x = ${x}")
    }
  }
  
}
